<% content_for :head do %>
<script type="text/javascript" charset="utf-8">
bkLib.onDomLoaded(function() {
	var myNicEditor = new nicEditor({
				fullPanel: true, 
				iconsPath: '/nicEdit/nicEditorIcons.gif', 
				maxHeight: 200
				/*onSave : function(content, id, instance) {
					$('#page_body').text(content);
					$('.edit_page').submit();	
				}*/
	}) //.panelInstance('page_body');
  myNicEditor.setPanel('nic_panel');
  myNicEditor.addInstance('real_body');
});
function hijack_link() {
	$('.nicEdit-frame').contents().find('a').click(function(){
		window.location.href = $(this).attr('href');
	})	
}
setTimeout("hijack_link()", 1000);
function ajaxSave() {
	$('#indicator').show();
	$('#page_body').val(nicEditors.findEditor('real_body').getContent());
	$('.edit_page').ajaxSubmit({
		success: function(){ $('#indicator').hide(); $('input[type=button]').blur() }
	});
	return false;
}
</script>
<% end %>
<% jquery_onload do %>
window.onbeforeunload = function(){
	// Resolve html entities mismatch between nicEdit and jQuery
	if(nicEditors.findEditor('real_body').getContent().unescapeHtmlEntities() != $('#page_body').val()) {
		//return confirm('저장되지 않은 내용이 있습니다.') 
		return '저장되지 않은 내용이 있습니다.'
	}	
};
$('.edit_page').submit(function(){
	$('#page_body').val(nicEditors.findEditor('real_body').getContent());
}); 
<% end %>

<% form_for @page do |form| %>
	<div id="title_area" class="clearfix">
		<%= page_title @page.title %>
		<div class="float right">
			<%#= link_to '취소', page_path(@page) %>
			<span id="indicator" class="hidden">Saving...</span>
			<%= button_to_function '저장', "ajaxSave()" %>
			<%= submit_tag '저장후 종료' %>
		</div>
	</div>
	<div id="nic_panel" style="width: 100%; margin: 5px 0 10px;"></div>
	<div id="real_body" style="width: 100%;">
		<%= w(@page.body) %>
	</div>
	<div class="hidden">
		<%= text_area_tag 'page[body]', w(@page.body), :id => 'page_body' %>
	</div>	
	<%#= hidden_field_tag 'page[body]', w(@page.body), :id => 'page_body' %>
<% end %>

<div id="summary_area" class="right clearfix">
	<div class="float left">
		<%#= link_to APP_CONFIG[:home_title], root_path unless @page.title == APP_CONFIG[:home_title] %>
	</div>
	<div id="version">
		<%= link_to "버전: #{@page.versions.current.number}, <span class=\"atby\">#{human_time(@page.created_at)}</span>" %>
	</div>	
</div>

<div id="related_pages">
	<h4>연관 페이지</h4>
	<%= empty_msg_for @related_pages, '이 페이지를 링크한 페이지가 없습니다.' %>
	<% unless @related_pages.empty? %>
	<ul>
		<% @related_pages.each do |page| %>
			<li>
				<%= link_to page.title, page_path(page) %>
				<span class="excerpt"><%= truncate(strip_tags_and_wiki(page.body), 30) %></span>
				<span class="atby">
					at <%= human_time(page.updated_at) %>
				</span>	
			</li>
		<% end %>
	</ul>	
	<% end %>
</div>	

<% content_for :sub_area do %>
	<%= render :partial => 'recent_pages' %>
<% end %>

<script type="text/javascript" charset="utf-8">
	
</script>
